package autocode

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
	autocodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
	"github.com/flipped-aurora/gin-vue-admin/server/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type GoodsInfoApi struct {
}

var goodsInfoService = service.ServiceGroupApp.AutoCodeServiceGroup.GoodsInfoService

// CreateGoodsInfo 创建GoodsInfo
// @Tags GoodsInfo
// @Summary 创建GoodsInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.GoodsInfo true "创建GoodsInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /goodsInfo/createGoodsInfo [post]
func (goodsInfoApi *GoodsInfoApi) CreateGoodsInfo(c *gin.Context) {
	var goodsInfo autocode.GoodsInfo
	_ = c.ShouldBindJSON(&goodsInfo)
	if err := goodsInfoService.CreateGoodsInfo(goodsInfo); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteGoodsInfo 删除GoodsInfo
// @Tags GoodsInfo
// @Summary 删除GoodsInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.GoodsInfo true "删除GoodsInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /goodsInfo/deleteGoodsInfo [delete]
func (goodsInfoApi *GoodsInfoApi) DeleteGoodsInfo(c *gin.Context) {
	var goodsInfo autocode.GoodsInfo
	_ = c.ShouldBindJSON(&goodsInfo)
	if err := goodsInfoService.DeleteGoodsInfo(goodsInfo); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteGoodsInfoByIds 批量删除GoodsInfo
// @Tags GoodsInfo
// @Summary 批量删除GoodsInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除GoodsInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /goodsInfo/deleteGoodsInfoByIds [delete]
func (goodsInfoApi *GoodsInfoApi) DeleteGoodsInfoByIds(c *gin.Context) {
	var IDS request.IdsReq
	_ = c.ShouldBindJSON(&IDS)
	if err := goodsInfoService.DeleteGoodsInfoByIds(IDS); err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateGoodsInfo 更新GoodsInfo
// @Tags GoodsInfo
// @Summary 更新GoodsInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.GoodsInfo true "更新GoodsInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /goodsInfo/updateGoodsInfo [put]
func (goodsInfoApi *GoodsInfoApi) UpdateGoodsInfo(c *gin.Context) {
	var goodsInfo autocode.GoodsInfo
	_ = c.ShouldBindJSON(&goodsInfo)
	if err := goodsInfoService.UpdateGoodsInfo(goodsInfo); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindGoodsInfo 用id查询GoodsInfo
// @Tags GoodsInfo
// @Summary 用id查询GoodsInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocode.GoodsInfo true "用id查询GoodsInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /goodsInfo/findGoodsInfo [get]
func (goodsInfoApi *GoodsInfoApi) FindGoodsInfo(c *gin.Context) {
	var goodsInfo autocode.GoodsInfo
	_ = c.ShouldBindQuery(&goodsInfo)
	if err, regoodsInfo := goodsInfoService.GetGoodsInfo(goodsInfo.ID); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"regoodsInfo": regoodsInfo}, c)
	}
}

// GetGoodsInfoList 分页获取GoodsInfo列表
// @Tags GoodsInfo
// @Summary 分页获取GoodsInfo列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocodeReq.GoodsInfoSearch true "分页获取GoodsInfo列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /goodsInfo/getGoodsInfoList [get]
func (goodsInfoApi *GoodsInfoApi) GetGoodsInfoList(c *gin.Context) {
	var pageInfo autocodeReq.GoodsInfoSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := goodsInfoService.GetGoodsInfoInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}

// GetGoodsInfoListDay 分页获取GoodsInfo列表
// @Tags GoodsInfo
// @Summary 分页获取GoodsInfo列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocodeReq.GoodsInfoSearch true "分页获取GoodsInfo列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /goodsInfo/getGoodsInfoList [get]
func (goodsInfoApi *GoodsInfoApi) GetGoodsInfoListDay(c *gin.Context) {
	var pageInfo autocodeReq.GoodsInfoSearchDay
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list := goodsInfoService.GetGoodsInfoListDay(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List: list,
		}, "获取成功", c)
	}
}
